/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    vector<int> largestValues(TreeNode* root) {
      vector<int>maxid;
      maxid.clear();
      queue<TreeNode*>node;
     if(root==NULL)return maxid;
      node.push(root);
      while(!node.empty())
      {
          int size=node.size();
          int maxnum=node.front()->val;
          while(size--)
          {
             auto front=node.front();
             node.pop();
            if(front->val>maxnum)maxnum=front->val;
             if(front->left)node.push(front->left);
             if(front->right)node.push(front->right);
          }
          maxid.push_back(maxnum);
      }
      return maxid;
    }
};
